<?php
    define('WP_USE_THEMES', false); 
    
    require('./wp-blog-header.php');
    require('./DBHandler.php');

    $dbHandler = new DBHandler;

    $courseid = '';
    $assignmentId = '';
    
    if ($_GET)
    {
        $courseId = $_GET['courseid'];
        $assignmentId = $_GET['assignmentid'];

        $submissions = $dbHandler->GetAllSubmissions($assignmentId);
        $assignment = $dbHandler->GetAssignment($assignmentId);
    }
?>

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <h2>Manage Submissions <?php echo " - ". $assignment->post_title; ?></h2>
        <a href="manageassignments.php?courseid=<?php echo $courseId?>">Back to Manage Assignments</a>
        <br/><br/>
        <a href="submitassignment.php?courseid=<?php echo $courseId?>&assignmentid=<?php echo $assignmentId?>&op=create">Submit Assignment</a>
        <table border="1">
            <tr>
                <th>Student Name</th>
                <th>Date Submitted</th>
                <th>Preview</th>
                <th>Edit</th>
                <th>Delete</th>
            </tr>
            <?php
                foreach($submissions as $submission)              
                {
                    echo "<tr>";
                    echo "<td>" . $submission->AuthorName . "</td>";
                    echo "<td>" . $submission->SubmissionDate . "</td>";
                    echo "<td><a href='PreviewAssignment.php?courseid=" . $courseId . "&assignmentid=" . $submission->SubmissionId . "'>Preview</a></td>";
                    echo "<td><a href='SubmitAssignment.php?courseid=" . $courseId . "&assignmentid=" . $assignmentId . "&subid=" . $submission->SubmissionId . "&op=edit'>Edit</a></td>";
                    echo "<td><a href='SubmitAssignment.php?courseid=" . $courseId . "&assignmentid=" . $assignmentId . "&subid=" . $submission->SubmissionId . "&op=delete'>Delete</a></td>";
                    echo "</tr>";
                }
            ?>
        </table>
    </body>
</html>
